package cn.tedu.file;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**本类用于测试字符输出流*/
public class TestOut2 {
    public static void main(String[] args) {
        method1();//用于测试普通字符输出流
        method2();//用于测试高效字符输出流
    }

    private static void method2() {
        BufferedWriter out = null;
        try {
//            out = new BufferedWriter(new FileWriter(new File("C:\\kaifa\\ready\\1.txt")));//覆盖输出
//            out = new BufferedWriter(new FileWriter("C:\\kaifa\\ready\\1.txt"));
//            out = new BufferedWriter(new FileWriter(new File("C:\\kaifa\\ready\\1.txt"),true));//追加输出
            out = new BufferedWriter(new FileWriter("C:\\kaifa\\ready\\1.txt",true));
            out.write(98);
            out.write(98);
            out.write(98);
            out.write(98);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method1() {
        FileWriter out = null;
        try {
//            out = new FileWriter(new File("C:\\kaifa\\ready\\1.txt"));//覆盖输出
//            out = new FileWriter("C:\\kaifa\\ready\\1.txt");
//            out = new FileWriter(new File("C:\\kaifa\\ready\\1.txt"),true);//追加输出
            out = new FileWriter("C:\\kaifa\\ready\\1.txt",true);
            out.write(97);
            out.write(97);
            out.write(97);
            out.write(97);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
